package org.example.cloudgetway.handler;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import java.lang.reflect.Method;
@Component
public class ApiIdempotentInceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        /*return HandlerInterceptor.super.preHandle(request, response, handler);*/
        System.out.println("拦截");
        final HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();
        boolean annotationPresent = method.isAnnotationPresent(AplidermpotentAnn.class);
        if ((annotationPresent && method.getAnnotation(AplidermpotentAnn.class).value())){
            /*HandlerInterceptor.super.preHandle(request, response, handler)*/
            return true;
        }else {
            return false;
        }
    }
}
